#!/bin/bash

# shellcheck disable=SC2120

# Provide source directive to shellcheck.
# shellcheck source=meta-facebook/meta-greatlakes/recipes-phosphor/state/phosphor-state-manager/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd

# TODO: check power status before do power off
# Set state effecter state: Entity ID 0x0000 for host power control, 0x2 for power off
EID=$(($1*10))
if ! pldmtool raw -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x02 -m "$EID"
then
    echo "Failed to set host$1 power off"
else
    echo "Host is power off"
fi
